<template>
  <page-header-wrapper>
    <page-tab-list></page-tab-list>
    <a-card :border="false">
      <a-form-model ref="ruleForm" :model="form" :rules="rules" :label-col="{ span: 4 }" :wrapper-col="{ span: 14 }">
        <a-form-model-item label="销售溢价" prop="rate">
          <a-input-number
            style="width: 200px; margin-right: 10px"
            v-model="form.rate"
            :min="0"
            :precision="2"
            placeholder="请输入销售溢价比例"
          />
          <span>%</span>
        </a-form-model-item>
        <a-form-model-item label="是否自动转单" prop="rate">
          <a-radio-group v-model="form.is_auth_trans" >
            <a-radio :value="0"> 关闭 </a-radio>
            <a-radio :value="1"> 开启 </a-radio>
          </a-radio-group>
        </a-form-model-item>
        <a-form-model-item label="是否自动更新商品" prop="rate">
          <a-radio-group v-model="form.cloud_is_update" >
            <a-radio :value="0"> 关闭 </a-radio>
            <a-radio :value="1"> 开启 </a-radio>
          </a-radio-group>
        </a-form-model-item>
        <a-form-model-item :wrapper-col="{ span: 14, offset: 4 }">
          <a-button type="primary" :loading="btnLoading" @click="onSubmit"> 保存 </a-button>
        </a-form-model-item>
      </a-form-model>
    </a-card>
  </page-header-wrapper>
</template>
<script>
import { setStoreRate, getStoreRate } from '@/api/store'
import tabList from '@/views/saas/components/tabList.vue'
export default {
  components: {
    tabList,
  },

  data() {
    return {
      tabList: [
        {
          key: 'purchaseGoodsList',
          name: '云仓选品库',
        },
        {
          key: 'goodsCloudList',
          name: '我的云仓',
        },
        {
          key: 'purchaseTransRecord',
          name: '云仓转单',
        },
        {
          key: 'businessPurchaseBalance',
          name: '我的账户',
        },
        {
          key: 'purchaseSetting',
          name: '云仓设置',
        },
        {
          key: 'purchaseGoodsUpdateLog',
          name: '商品更新记录',
        },
        // {
        //     key:'businessPurchaseRecharge',
        //     name:'充值记录'
        // }
      ],

      form: {
        rate: '10.00',
        is_auth_trans: 0,
        cloud_is_update: 0
      },

      rules: {
        rate: [{ required: true, message: '销售溢价', trigger: 'blur' }],
      },

      btnLoading: false,
    }
  },
  created() {
    this.getStoreRate()
  },
  methods: {
    // 获取配置数据
    async getStoreRate() {
      this.btnLoading = true
      const res = await getStoreRate()
      this.btnLoading = false
      if (res.code == 0) {
        this.form = res.data
      }
    },
    onSubmit() {
      this.$refs.ruleForm.validate(async (valid) => {
        if (valid) {
          this.btnLoading = true
          const res = await setStoreRate(this.form)
          this.btnLoading = false

          if (!res.code) {
            this.$message.success('保存成功！')
          } else {
            this.$message.error(res.msg)
          }
        } else {
          return false
        }
      })
    },
  },
}
</script>

<style lang="scss" scoped></style>
